/**
 * @author junyu33
 * 2022,05,07
 */
import java.util.Scanner;

public class Main {
    static Scanner input = new Scanner(System.in);

    /**
     * program entry
     * @param args
     */
    public static void main(String[] args) {
        System.out.print("Please input society's name: ");
        Society society = new Society(input.next());
        System.out.println("Welcome to society " + society.getName());
        run(society);
    }

    /**
     * get choice from menu
     * @return choice
     */
    public static int getchoice() {
        try {
            int x = input.nextInt();
            if(x < 0 || x > 5) {
                System.out.println("Invalid input");
                return -1;
            }
            return x;
        } catch (NumberFormatException nfe) {
            System.out.println("Invalid input");
            return -1;
        }
    }

    /**
     * program's menu
     * @param demo
     */
    public static void run(Society demo) {
        while(true) {
            System.out.println("Here are your choices:\n"
                    + "[0] Quit\n"
                    + "[1] Add a standard member\n"
                    + "[2] Add a senior member\n"
                    + "[3] Add a committee member\n"
                    + "[4] Get total fee\n"
                    + "[5] Show info\n"
                    + "choice> ");
            String name, address; int fee;
            switch (getchoice()) {
                case 0: return;
                case 1:
                    System.out.println("input member's name and address:");
                    name = input.next();
                    address = input.next();
                    demo.addMember(name, address);
                    break;
                case 2:
                    System.out.println("input senior member's name, address and fee:");
                    name = input.next();
                    address = input.next();
                    try {
                        fee = input.nextInt();
                    } catch (NumberFormatException nfe) {
                        System.out.println("Invalid input");
                        break;
                    }
                    demo.addSeniorMember(name, address, fee);
                    break;
                case 3:
                    System.out.println("please type one senior member's name:");
                    name = input.next();
                    if(demo.findSeniorMember(name) != null)
                        demo.addCtteeMember(demo.findSeniorMember(name));
                    break;
                case 4:
                    System.out.println(demo.getFeeTotal());
                    break;
                case 5:
                    demo.showInfo();
                    break;
                default:
            }
        }
    }
}
